﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Castle.ActiveRecord;
using NHibernate.Criterion;
using LIB;
using System.Collections;

public partial class template_danhmucnhaquanhuyen : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {

            int pageIndex = ConvertUtility.ToInt32(Request.QueryString["page"]);

            if (pageIndex > 0)
            {
                bindHome(pageIndex);
                hidPageIndex.Value = pageIndex.ToString();
            }
            else
            {
                bindHome(1);
                hidPageIndex.Value = "1";
            }
        }
        catch (Exception ex) { }
    }
    protected void bindHome(int pageIndex)
    {
        int quanID = ConvertUtility.ToInt32(Request.QueryString["quanHuyenID"]);
        int mucgiaID = ConvertUtility.ToInt32(Request.QueryString["mucGiaID"]);

        string lstCatID = ConvertUtility.ToString(Request.QueryString["lstCatID"]);
        int soCatID = 0;
        if (!String.IsNullOrEmpty(lstCatID))
        {
            lstCatID = lstCatID.Substring(0, lstCatID.Length - 1);
            soCatID = lstCatID.Split(',').Length;
        }
        string orderBy = ConvertUtility.ToString(Request.QueryString["orderBy"]);
        if (!String.IsNullOrEmpty(orderBy))
        {
            orderBy = orderBy.Substring(0, orderBy.Length - 1);
        }
        Home_Info[] lstHome = Home_Info.searchHomeInQuanHuyen(quanID,mucgiaID,lstCatID, soCatID, orderBy);

        repDanhMucNha.DataSource = lstHome.Skip((pageIndex - 1) * 16).Take(16);
        repDanhMucNha.DataBind();

        int totalPage = (int)Math.Ceiling(ConvertUtility.ToDouble(lstHome.Length) / 16);
        pagerbot.Text = ConvertUtility.buildSimplePaging(totalPage, pageIndex);

    }
}